<template>
  <div class="risk">
    <div class="add" @click="add()">添加</div>
    <eagle-page-list
      ref="eaglePageList"
      @bindData="bindData"
      :queryParams="queryParams"
      :controller="controller"
      :conditions="conditions"
      :pageSize="20"
    >
      <template #list>
        <div
          class="block"
          v-for="item in list"
          :key="item.ID"
          @click="toDangerTemplate(item)"
        >
          <div class="blockCell">{{ item.TName }}</div>
          <span class="sub-cell">暂无描述</span>
        </div>
      </template>
    </eagle-page-list>
    <!--检查表-->
    <van-popup
      v-model="CheckTableShow"
      round
      position="bottom"
      :style="{ height: '80%' }"
    >
      <div class="popup-title"></div>
      <div class="popup-content">
        <CheckTable @cb="_chooseCheckTable" />
      </div>
    </van-popup>
  </div>
</template>

<script>
import { getEquDangerTemp, AddTemplateToEquDanger } from "@/api/equipment";
import CheckTable from "@/components/CheckTable/CheckTable.vue";
export default {
  components: {
    CheckTable,
  },
  data() {
    return {
      list: [],
      conditions: {},
      controller: "/EquDangerTemp",
      queryParams: {
        dataType: "EquipmentTemplate",
        equipmentCode: this.$route.query.equipmentCode,
      },
      CheckTableShow: false,
      isJG:false
    };
  },
  created() {
    this.isJG= this.$store.state.CompanyType=='JG'

  },
  methods: {
    bindData(data) {
      this.list = [];
      if (data) {
        this.list = data;
      }
    },
    add() {
      this.CheckTableShow = true;
    },
    // 选择检查表回调
    _chooseCheckTable(params) {
      let _this = this;
      _this.CheckTableShow = false;
      if (params.TCodes) {
        const formData = {
          ...params,
          EquipmentCode: _this.$route.query.equipmentCode,
        };
        _this.$axios
          .post("/EquDangerTemp/AddTemplateToEquDanger", formData)
          .then((res) => {
            _this.$toast.success("添加成功！");
            _this.$refs.eaglePageList.confirm();
          });
      }
    },
    toDangerTemplate(item) {
      let url = this.isJG?"/Danger/DangerTemplateDetailJG":"/Danger/DangerTemplateDetail"
      this.$router.push({
        path: url,
        query: {
          areaCode: this.$route.query.areaCode,
          areaName: this.$route.query.areaName,
          areaType: this.$route.query.areaType,
          areaNo: this.$route.query.areaNo,
          tCode: item.TCode,
        },
      });
    },
  },
};
</script>
<style lang="less" scoped>
.risk {
  background: #e8f1f8;
}
.block {
  margin: 10px 0;
  background: #fff;
  padding: 10px;
  border-radius: 5px;
}
.blockCell {
  color: #333;
  font-size: 16px;
  line-height: 30px;
}
.info_search {
  padding: 10px;
  border-radius: 5px !important;
  .van-field__control {
    background-color: #ffffff !important;
  }
}
.sub-cell {
  color: #666;
  font-size: 12px;
  line-height: 25px;
}
</style>
